-module(increm_service).
-behavior(gen_server).
-export([start/0,init/1,handle_call/3,handle_cast/2,handle_info/2,terminate/2,code_change/3]).
-define(SERVER    , ?MODULE).
start()  ->
	case gen_server:start({local, ?SERVER}, ?MODULE, [], []) of 
	{ok,_} ->
		ok;
	{error,{already_started,_}} ->
		ok;
	{error,Reason} ->
		io:format("start ~s service failure with ~p~n",[?SERVER,Reason])
	end.
	
init(_) ->
	{ok,[]}.
handle_call({new,Prefix},_,Qs) ->
		case lists:keyfind(Prefix,1,Qs) of
		{Prefix,Index} ->
			{reply,lists:flatten(io_lib:format("~s~p",[Prefix,Index + 1])),[{Prefix,Index + 1}|lists:keydelete(Prefix,1,Qs)]};
		false ->
			{reply,lists:flatten(io_lib:format("~s~p",[Prefix,0])),[{Prefix,0}|Qs]}
		end;
	
handle_call(_,_,State) ->
	{reply, {error,"no func define", State}}.
handle_cast(_, State) ->
	{noreply,State}.
handle_info(_, State) ->
	{noreply,State}.
terminate(_, _) ->
	ok.
code_change(_, State, _) ->
	{ok,State}.